package com.wan37.logic.copy;

import com.wan37.logic.copy.boss.BossSceneVO;
import com.wan37.logic.domain.vo.MonsterVO;
import com.wan37.logic.service.cache.MonsterServiceCache;
import com.wan37.logic.service.cache.SceneServiceCache;
import com.wan37.protobuf.constant.BossSceneCommon;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @author : luoyong
 * @date : 2020-06-30 15:50
 **/
@Component
public class BossSceneManager {
    @Autowired
    private MonsterServiceCache monsterServiceCache;
    private SceneServiceCache sceneServiceCache;
    private Map<String, BossSceneVO> bossSceneVOMap = new HashMap<>();

    public void registerBossScene(String bossSceneId, List<String> bossIdList, String preSceneId) {
        List<MonsterVO> bossVOList = new LinkedList<>();
        bossIdList.forEach(bossId -> {
            MonsterVO bossVO = new MonsterVO();
            BeanUtils.copyProperties(monsterServiceCache.getMonsterServiceMap().get(bossId).getMonsterVO(), bossVO);
            bossVOList.add(bossVO);
        });
//        BossSceneVO bossSceneVO = new BossSceneVO();
//        bossSceneVO.setCreateTime(System.currentTimeMillis());
//        bossSceneVO.setEndTime(bossSceneVO.getCreateTime() + BossSceneCommon.DURATION_TIME);
//        bossSceneVO.setBossVO(bossVOList);
//        bossSceneVO.setId(id);
//        bossSceneVO.setPreId(preSceneId);
//        bossSceneVOMap.put(id, bossSceneVO);
    }

    public void deleteScene(String sceneId) {
        if (sceneServiceCache.getSceneServiceMap().containsKey(sceneId)) {
            sceneServiceCache.getSceneServiceMap().get(sceneId).getGoSceneIdSet().forEach(oldSceneId -> {
                sceneServiceCache.getSceneServiceMap().get(oldSceneId).getGoSceneIdSet().remove(sceneId);
                sceneServiceCache.sceneNameToIdMap.remove(sceneId);
                sceneServiceCache.sceneSet.remove(sceneId);
            });
        }
    }
}
